/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

/**
 * <p>Project: javase2203 - T7
 * <p>Powered by webrx On 2022-08-09 10:21:45
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T7 {
    Object a = new Object();

    void work() {
        String t = Thread.currentThread().getName();
        System.out.printf("%s线程启动...%n", t);
        try {
            if ("over".equalsIgnoreCase(t)) {
                Thread.sleep(5000);
                synchronized (a) {
                    //a.notify();
                    a.notifyAll();
                }
            } else {
                synchronized (a) {
                    a.wait();
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        System.out.printf("%s结束%n", t);
    }

    public static void main(String[] args) {
        var t = new T7();
        new Thread(t::work, "t1").start();
        new Thread(t::work, "t2").start();
        new Thread(t::work, "t3").start();
        new Thread(t::work, "t4").start();
        new Thread(t::work, "over").start();
    }
}
